// pages/auth/auth.js
import {
  login,request
} from '../../utlis/asyncWx';
// ES7兼容插件
// import regeneratorRuntime from "../../lib/runtime/runtime";
Page({
  data: {
  },
  async handleGetUserInfo(e) {
    try {
      console.log('授权', e.detail);
      const { encryptedData, errMsg, iv, rawData, signature } = e.detail
      let loginParams = { encryptedData, errMsg, iv, rawData, signature }
      const { code } = await login()
      console.log('code', code);
      // 获取token
      const { token } = await request({ url: "users/wxlogin", data: loginParams, method: "post" })
      
      wx.setStorageSync('token', 'token')
      // 返回上一页
      wx.wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error);
    }

  },
  onLoad: function (options) {
    // console.log(request);
  },
})